package jd.client;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @author Denis Migol
 * 
 */
public class ResponseFactory {

	/**
	 * 
	 */
	private static final Map<String, Class<? extends Response>> GETS = new HashMap<String, Class<? extends Response>>();

	/**
	 * 
	 */
	private static final Map<Class<? extends Request>, Class<? extends Response>> ACTIONS = new HashMap<Class<? extends Request>, Class<? extends Response>>();

	/**
	 * 
	 * @param request
	 * @param response
	 */
	public static void register(final String request, final Class<? extends Response> response) {
		GETS.put(request, response);
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static Response getResponse(final String request) {
		try {
			return GETS.get(request).newInstance();
		} catch (final Exception e) {
		}
		return null;
	}

	/**
	 * 
	 * @param request
	 * @param response
	 */
	public static void register(final Class<? extends Request> request, final Class<? extends Response> response) {
		ACTIONS.put(request, response);
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static Response getResponse(final Request request) {
		try {
			return ACTIONS.get(request.getClass()).newInstance();
		} catch (final Exception e) {
		}
		return null;
	}
}
